package com.itheima.homeweek;

import javax.crypto.spec.PSource;
import java.util.Random;

public class HomeWeek05 {//获取一个长度为10000的数组，数组中的元素是随机生成的1到10000的整数。
    //编写冒泡排序算法对该数组进行排序，并计算排序所需的时间
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        Random r = new Random();
        int[] arr = new int[10000];
        for (int i = 0; i < 10000; i++) {
            arr[i] = r.nextInt(10000) + 1;
        }
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - (1+i); j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        for(int i = 0;i<arr.length;i++){
            System.out.println(arr[i]);
        }
        long end = System.currentTimeMillis();
        System.out.println("程序运行时间为:" + (end - start) + "毫秒");
    }
}
